import javax.crypto.SecretKey;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.SecretKeySpec;


public class BuiltIn implements Runnable{
	// Takes a 7-byte quantity and returns a valid 8-byte DES key.
	// The input and output bytes are big-endian, where the most significant
	// byte is in element 0.
	public static byte[] addParity(byte[] in) {
	    byte[] result = new byte[8];

	    // Keeps track of the bit position in the result
	    int resultIx = 1;

	    // Used to keep track of the number of 1 bits in each 7-bit chunk
	    int bitCount = 0;

	    // Process each of the 56 bits
	    for (int i=0; i<56; i++) {
	        // Get the bit at bit position i
	        boolean bit = (in[6-i/8]&(1<<(i%8))) > 0;

	        // If set, set the corresponding bit in the result
	        if (bit) {
	            result[7-resultIx/8] |= (1<<(resultIx%8))&0xFF;
	            bitCount++;
	        }

	        // Set the parity bit after every 7 bits
	        if ((i+1) % 7 == 0) {
	            if (bitCount % 2 == 0) {
	                // Set low-order bit (parity bit) if bit count is even
	                result[7-resultIx/8] |= 1;
	            }
	            resultIx++;
	            bitCount = 0;
	        }
	        resultIx++;
	    }
	    return result;
	}

	public void run() {
		// Get the 56-bit value
		byte[] raw = new byte[]{0x01, 0x72, 0x43, 0x3E, 0x1C, 0x7A, 0x55};
		byte[] keyBytes = addParity(raw);

		// You can check that the parity has been set properly
		try {
		    boolean b = DESKeySpec.isParityAdjusted(keyBytes, 0);
		} catch (java.security.InvalidKeyException e) {
		    // The DES is invalid
		}

		// Convert the bytes into a SecretKey suitable for use by Cipher
		SecretKey key = new SecretKeySpec(keyBytes, "DES");

		
	}

	
}
